package com.koron.css2.newProjectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.PjPubUpMaterial;
import com.koron.css2.newProjectCenter.mapper.PjPubUpMaterialMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.PingYin;
import org.swan.bean.MessageBean;

/**
 * @Author: 苏小龙
 * @CreateTime: 2024-12-04
 * @Description: 材料信息
 * @Version: 1.0
 */
public class PjPubUpMaterialUpdate implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjPubUpMaterial pubUpInvoice = JsonUtils.objectToPojo(req.getData(), PjPubUpMaterial.class);
            PjPubUpMaterialMapper pjPubUpInvoiceMapper= factory.getMapper(PjPubUpMaterialMapper.class);
            // 1. updateTime,updateAccount,updateName
            pubUpInvoice.setUpdateInfo(userInfo);
            pubUpInvoice.setMnemonicCode(PingYin.getInstance().getSelling(pubUpInvoice.getName(), true, "?"));
            // 2. 更新数据
            if (pubUpInvoice.getSalesPrice().isEmpty())
                pubUpInvoice.setSalesPrice(null);
            if (pubUpInvoice.getCostPrice().isEmpty())
                pubUpInvoice.setCostPrice(null);
            pjPubUpInvoiceMapper.update(pubUpInvoice);
            // 3. 返回结果
            return MessageBean.create(Constant.MESSAGE_INT_SUCCESS,"材料信息更新成功",null);
        } catch (Exception e) {
            logger.error("材料信息更新失败",e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL,"材料信息更新失败",null);
        }
    }
}
